package com.warehouse.service.impl;

import com.warehouse.entity.Customer;
import com.warehouse.entity.CustomerExample;
import com.warehouse.mapper.CustomerMapper;
import com.warehouse.service.CustomerService;
import com.warehouse.utils.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @program: warehouse
 * @description: 客户管理业务层
 * @author: xiaojiu
 * @create: 2021-01-13 22:43
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired(required = false)
    private CustomerMapper customerMapper;
//    @Autowired(required = false)
////    private CustomerExample example;
    @Autowired(required = false)
    private IdWorker idWorker;
    @Override
    public List<Customer> findAllCustomers(Integer currentPage, Integer pageSize) {
        CustomerExample example =new CustomerExample();
        example.setOffset((currentPage-1)*pageSize);
        example.setLimit(pageSize);
        return customerMapper.selectByExample(example);
    }

    @Override
    public boolean addCustomers(Customer customer) {
        String id=idWorker.nextId()+"";
        customer.setId(id);
        customer.setCreateTime(new Date());
        System.out.println(id);
        int i = customerMapper.insertSelective(customer);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean delCustomers(String id) {
        int i = customerMapper.deleteByPrimaryKey(id);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean editCustomer(Customer customer) {
        int i = customerMapper.updateByPrimaryKeySelective(customer);
        if(i>0){
            return true;
        }
        return false;
    }

    @Override
    public Customer findOneBy(String cuntomNum) {
        Customer customer = customerMapper.selectByPrimaryKey(cuntomNum);

        return customer;
    }

    @Override
    public List<Customer> findCustomer(Customer customer) {
        List<Customer> customer1=customerMapper.findCustomer(customer);
        return customer1;
    }
}
